<template>
  <Layout>
    <div style="min-height: 600px">
      <el-card shadow="never" style="min-height: 400px">
        <div slot="header">
          <el-row>
            <el-col :span="12">
              <span>{{project.name}}</span>
            </el-col>
            <el-col :span="12">
              <div style="text-align: right;">
                <el-button @click="share" style="padding: 3px 0" type="text" icon="el-icon-share">分享</el-button>
                <el-button
                  @click="goGithub(project.url)"
                  style="padding: 3px 0"
                  type="text"
                  icon="el-icon-back"
                >前往GitHub</el-button>
                <el-button
                  @click="more"
                  style="padding: 3px 0"
                  type="text"
                  icon="el-icon-more-outline"
                >更多项目</el-button>
              </div>
            </el-col>
          </el-row>
        </div>
        <div style="font-size: 0.9rem;line-height: 1.5;color: #606c71;">
          发布 {{$util.utcToLocal(project.created_at)}}
          <br />
          更新 {{$util.utcToLocal(project.updated_at)}}
        </div>
        <div
          style="font-size: 1.1rem;line-height: 1.5;color: #303133;padding: 20px 0px 0px 0px"
        >{{project.description}}</div>
        <div
          style="font-size: 1.1rem;color: #303133;padding: 15px 0px 15px 0px;border-bottom: 1px solid #E4E7ED;"
        >
          <el-row>
            <el-col :span="16" style="padding-top: 5px">
              <el-tooltip
                effect="dark"
                :content="'star '+project.stargazers_count"
                placement="bottom"
              >
                <i class="el-icon-star-off" style="margin: 0px 5px 0px 0px"></i>
              </el-tooltip>
              {{project.stargazers_count}}
              <el-tooltip
                effect="dark"
                :content="'watch '+project.watchers_count"
                placement="bottom"
              >
                <i class="el-icon-view" style="margin: 0px 5px 0px 15px"></i>
              </el-tooltip>
              {{project.watchers_count}}
              <el-tooltip effect="dark" :content="'fork '+project.forks_count" placement="bottom">
                <i class="el-icon-bell" style="margin: 0px 5px 0px 15px"></i>
              </el-tooltip>
              {{project.forks_count}}
            </el-col>
            <el-col :span="8" style="text-align: right;">
              <el-tag
                size="small"
                type="danger"
                v-if="project.license"
                style="margin-right: 10px"
              >{{project.license.key}}</el-tag>
              <el-tag size="small" type="success" v-if="project.language">{{project.language}}</el-tag>
            </el-col>
          </el-row>
        </div>
        <div
          v-loading="!content"
          v-html="content"
          class="markdown-body"
          style="padding-top: 20px"
        ></div>
        <!-- <div v-if="!content" style="padding: 20px 0px 20px 0px;text-align: center">
          <font style="font-size: 30px;color:#dddddd ">
            <b>还没有介绍 (╯°Д°)╯︵ ┻━┻</b>
          </font>
        </div> -->
      </el-card>
    </div>
  </Layout>
</template>

<page-query>
query($id: ID) {
  projects(id: $id) {
    id
    name
    description
    updated_at
    created_at
    html_url
    stargazers_count
    forks_count
    watchers_count
    language
    license {
      key
    }
  }
}
</page-query>

<script>
import projectApi from "../../api/project";

export default {
  data() {
    return {
      loading: false,
      content: null
    };
  },
  computed: {
    project() {
      let proj = Object.assign({}, this.$page.projects);
      return proj;
    }
  },
  async mounted() {
    let base64 = require("js-base64").Base64;
    const { data } = await projectApi.single(this.project.name);
    this.content = this.$markdown(base64.decode(data.content));
  },
  methods: {
    goGithub(url) {
      window.open(url);
    },
    more() {
      this.$router.push("/project");
    },
    share(i) {
      this.$util.copy(this.projects[i].html_url);
      this.$message({
        message: "链接已复制,去分享给好友吧!!",
        type: "success"
      });
    }
  }
};
</script>